package org.jugile.demo.web;

import java.util.ArrayList;
import java.util.List;

import org.jugile.util.Blob;
import org.jugile.util.Vo;
import org.jugile.web2.Component;
import org.jugile.web2.Response;

public class Main extends Component {

	public String getHello() {
		return "proto msg";
	}
	
	public Response get() {
		// get method is optional - default get() from Component does the default handling
		if ("json".equals(param("type"))) {
			Vo vo = new Vo();
			vo.set("name","Smith Jason");
			vo.set("age", 30);
			vo.set("address", new Vo().set("street", "New York St 200").set("zip", "00300"));
			return new Response(vo);			
		}
		return null; // default handler
	}
	
	public boolean needsAuthentication() { return false; }
	
	private String fname = "";
	public String getFname() { return fname; }
	
	private String lname = "";
	public String getLname() { return lname; }
	
	public void actionDoSend() {
		fname = param("fname");
		lname = param("lname");
		String text = param("textblock");
		print("DoSend: fname="+ fname + " lname=" + lname);
		print("text="+text);
	}
	
	public void actionMultipartDoSend() {
		fname = param("fname");
		lname = param("lname");
		String text = param("textblock");
		print("MultipartDoSend: fname="+ fname + " lname=" + lname);
		print("text="+text);
		Blob b1 = cycle().getFile("file1");
		print("size: "+ b1.getSize());
		b1.writeBytes("data/"+b1.getFilename());

	}
}
